{
    MyDesktop.AddCategoryForm = new Ext.form.FormPanel({
        id          : 'CategoryFormPanel',
        url         : '<?=BASE_URL?>/<?=$this->currentController?>/add-process',
        width       : 730,
        defaultType : 'textfield',
        autoScroll  : true,
        frame       : true,
        items       : [{
                fieldLabel : '<?=$this->translate->_("Category Name")?>',
                name       : 'name',
                id         : 'name',
                style      : 'width:98%',
                allowBlank : false,
                minLength  : 3
            }, {
                fieldLabel : "<?=$this->translate->_('Category Id')?>",
                name       : 'categoryId',
                id         : 'categoryId',
                value      : "<?=$this->categoryId?>",
                readOnly   : true,
                style      : 'width:98%'
            }, {
                fieldLabel : "<?=$this->translate->_('Parent Category')?>",
                name       : 'ParentName',
                id         : 'ParentName',
                value      : "<?=$this->strParent?>",
                readOnly   : true,
                style      : 'width:98%'
            }, {
                fieldLabel : "<?=$this->translate->_('Parent Id')?>",
                name       : 'parentid',
                id         : 'parentid',
                value      : '<?=$this->pid?>',
                readOnly   : true,
                style      : 'width:98%'
            }]
    });

    MyDesktop.AddCategoryPanel = Ext.extend(Ext.app.Module, {
        createWindow : function() {
            var desktop = app.getDesktop();
            var win = desktop.getWindow('addCategoryPanel');
            if (!win) {
                win = desktop.createWindow({
                    id          : 'addCategoryPanel',
                    title       : "<?=$this->translate->_('Category Management')?>",
                    width       : <?=$this->winWidth?>,
                    height      : <?=$this->winHeight?>,
                    iconCls     : 'icon-grid',
                    layout      : 'fit',
                    maximizable : false,
                    tbar        : [{
                        id      : 'add-category',
                        text    : "<?=$this->translate->_('Save')?>",
                        icon    : '<?=ICONS_DIR?>/newuser16x16.png',
                        cls     : "x-btn-text-icon",
                        handler : function() { // submit code here
                            var form = MyDesktop.AddCategoryForm.form;
                            form.submit({
                                waitMsg : "<?=$this->translate->_('Please wait')?>",
                                reset   : false,
                                success : function(f, a) {
                                    var message = "<?=$this->translate->_('Can\'t save to DB!')?>";
                                    try {
                                        message = a.result.message;
                                    } catch (ex) {
                                    }
                                    // MyDesktop.GridCategory.getStore().reload();
                                    MyDesktop.GridCategory.expandAll();
                                    win.close();
                                    Ext.Msg
                                            .alert(
                                                    "<?=$this->translate->_('Status')?>",
                                                    message);
                                },
                                failure : function(f, a) {
                                    var message = "<?=$this->translate->_('Your form is not valid!')?>";
                                    try {
                                        message = a.result.message;
                                    } catch (ex) {
                                    }
                                    Ext.Msg
                                            .alert(
                                                    "<?=$this->translate->_('Status')?>",
                                                    message);
                                }
                            });
                        }
                    }, {
                        id      : 'refresh',
                        text    : "<?=$this->translate->_('Reset')?>",
                        icon    : '<?=ICONS_DIR?>/refresh16x16.png',
                        cls     : "x-btn-text-icon",
                        handler : function() {
                            MyDesktop.AddCategoryForm.getForm().reset();
                        }
                    }, {
                        id      : 'noneparent',
                        text    : "<?=$this->translate->_('None parent')?>",
                        icon    : '<?=ICONS_DIR?>/refresh16x16.png',
                        cls     : "x-btn-text-icon",
                        handler : function() {
                            MyDesktop.AddCategoryForm.findById('ParentName')
                                    .setValue('');
                            MyDesktop.AddCategoryForm.findById('parentid')
                                    .setValue('<?=$this->rootId?>');
                        }
                    }],
                    items       : [MyDesktop.AddCategoryForm],
                    listeners   : {
                        render : function() {
                            //alert(MyDesktop.GridCategory.getStore().getNodeParent(MyDesktop.GridCategory.getStore().active_node));
                            if (0 == MyDesktop.AddCategoryForm
                                    .findById('parentid').value) {
                                MyDesktop.AddCategoryForm.findById('parentid')
                                        .setValue('<?=$this->rootId?>');
                            }
                        }
                    }
                });
            }
            win.show();
        }
    });

    var AddCategoryPanel = new MyDesktop.AddCategoryPanel();
    AddCategoryPanel.createWindow();

    Ext.get('ParentName').on('focus', function() {
                alert('Click me!');
            });
}